package cn.tedu_two.tedu_two;

import java.util.*;

public class Test3 {
    public static  void main(String[] args) {
        Map<Integer,String> m=new HashMap();
        m.put(1,"谢");
        m.put(2,"郜");
        m.put(3,"晨");
        m.put(4,"晨");
        System.out.println(m.put(5,"yue"));//null
        System.out.println(m);

        Set<Integer> s=m.keySet();
        System.out.println(m.keySet()+"~~");
        for(Integer x:s){
            String value=m.get(x);
            System.out.println(x+" "+value);
        }

        Collection<String> c=m.values();
        System.out.println(c);

        Set<Map.Entry<Integer,String>> ss=m.entrySet();
        for(Map.Entry<Integer,String> x:ss){
            Integer key= x.getKey();
            String value=x.getValue();
            System.out.println(key+" ~ "+value);
        }

        //遍历方式1：keySet ()
        Set set = m.keySet();
        Iterator it = set.iterator();
        while(it.hasNext()) {
            Integer key = (Integer) it.next();
            String val = m.get(key);
            System.out.println(key+"="+val);
        }

        //遍历方式2：entrySet ()
        Set set2 = m.entrySet();
        Iterator it2 = set2.iterator();
        while(it2.hasNext()) {
            Map.Entry en = (Map.Entry) it2.next();
            Integer key = (Integer) en.getKey();
            String value = (String) en.getValue();
            System.out.println(key+"=="+value);

        }
     }
}
